package com.hzqc.wxaapp.configure;

import com.hzqc.wxaapp.sdk.*;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * The type Wxa config.
 *
 * @author xiafang
 * @since 2022 /8/15 10:38
 */
@Configuration(proxyBeanMethods = false)
public class WxaConfig {

    /**
     * 小程序token缓存
     *
     * @return the mini app token storage
     */
    @Bean
    public MiniAppTokenStorage miniAppTokenStorage() {
        return new MiniAppTokenStorageImpl();
    }

    /**
     * 小程序客户端信息服务
     *
     * @return the mini app client service
     */
    @Bean
    public MiniAppClientService miniAppClientService() {
        return new MiniAppClientServiceImpl();
    }

    /**
     * 小程序Token服务
     *
     * @param restTemplateBuilder  the rest template builder
     * @param miniAppTokenStorage  the mini app token storage
     * @param miniAppClientService the mini app client service
     * @return the WeChat app token service
     */
    @Bean
    public WechatAppTokenService wechatAppTokenService(RestTemplateBuilder restTemplateBuilder,
                                                       MiniAppTokenStorage miniAppTokenStorage,
                                                       MiniAppClientService miniAppClientService) {
        return new WechatAppTokenService(restTemplateBuilder, miniAppTokenStorage, miniAppClientService);
    }

    /**
     * 小程序UrlScheme生成服务
     *
     * @param wechatAppTokenService the WeChat app token service
     * @return the WeChat app url scheme service
     */
    @Bean
    public WechatAppUrlSchemeService wechatAppUrlSchemeService(WechatAppTokenService wechatAppTokenService){
        return new WechatAppUrlSchemeService(wechatAppTokenService);
    }

    /**
     * 小程序UrlLink服务
     *
     * @param wechatAppTokenService the WeChat app token service
     * @return the WeChat app url link service
     */
    @Bean
    public WechatAppUrlLinkService wechatAppUrlLinkService(WechatAppTokenService wechatAppTokenService){
        return new WechatAppUrlLinkService(wechatAppTokenService);
    }

}
